//package com.water.expert.extraction.controller;
//
//import java.util.Iterator;
//
//import org.springframework.http.ResponseEntity;
//import org.springframework.security.core.annotation.AuthenticationPrincipal;
//import org.springframework.security.oauth2.client.OAuth2AuthorizedClient;
//import org.springframework.security.oauth2.client.OAuth2AuthorizedClientService;
//import org.springframework.security.oauth2.core.user.OAuth2User;
//import org.springframework.ui.Model;
//import org.springframework.web.bind.annotation.GetMapping;
//import org.springframework.web.bind.annotation.RestController;
//
//import jakarta.servlet.http.HttpServletRequest;
//
///**
// * 处理 授权成功后的回调
// */
//@RestController
//public class OAuth2LoginController {
//    private final OAuth2AuthorizedClientService authorizedClientService;
//    
//    public OAuth2LoginController(OAuth2AuthorizedClientService authorizedClientService) {
//        this.authorizedClientService = authorizedClientService;
//    }
//    
//    @GetMapping("/login/oauth2/code/expertextractionservice")
//    public String oauth2Callback(Model model, @AuthenticationPrincipal OAuth2User user) {
//        model.addAttribute("name", user.getAttribute("name"));
//        model.addAttribute("email", user.getAttribute("email"));
//        return "home";
//    }
//    
//    @GetMapping("/token")
//    public ResponseEntity<String> getAccessToken(HttpServletRequest request,@AuthenticationPrincipal OAuth2User user) {
//    	if(user == null) {
//    		Iterator<String> iter = request.getHeaderNames().asIterator();
//    		StringBuilder result = new StringBuilder();
//        	while(iter.hasNext()) {
//        		String headerName = iter.next();
//        		String headerValue = request.getHeader(headerName);
//        		result.append(headerName).append(":").append(headerValue).append(",");
//        		System.out.println(">>"+headerName+":"+headerValue);
//        	}
//        	return ResponseEntity.ok(result.toString());
//    	}
//        OAuth2AuthorizedClient authorizedClient = authorizedClientService.loadAuthorizedClient("expertextractionservice", user.getName());
//        String token= authorizedClient.getAccessToken().getTokenValue();
//        return ResponseEntity.ok(token);
//    }
//
//    @GetMapping("/")
//    public ResponseEntity<Void> home(HttpServletRequest request, @AuthenticationPrincipal OAuth2User user) {
//    	 return ResponseEntity.ok().<Void>build();
//    }
//}
